<script setup lang="ts">
import { assetChart } from '@/store/modules/asset-chart';
import { computed, ref } from 'vue';

const emits = defineEmits(['change']);
const list = assetChart();

const dataList = list.chartList;
const activeID = ref(0);
function onSelectTilte(id: number) {
  list.chartList = dataList;
  activeID.value = id;
  list.undateChartList(id);
  if (id === 0) {
    list.chartList = dataList;
  }
}

function onMouseente(name: string) {
  emits('change', name, 1);
}
function onMouseup(name: string) {
  emits('change', name);
}
</script>

<template>
  <div class="left">
    <div>
      <div
        v-for="item in list.chartTitleList"
        :key="item.id"
        class="left-title"
        @click.stop="onSelectTilte(item.id)"
        :class="{ 'active-assets-tilte': activeID === item.id }"
      >
        {{ item.name }}
      </div>
    </div>
    <div
      class="left-img"
    >
      <div
        v-for="(img, i) in list.chartList"
        :key="i"
        draggable="true"
        @mouseenter="onMouseente(img.componentName)"
        @mouseup="onMouseup(img.componentName)"
      >
        <div class="desc">{{ img.name }}</div>
        <div><img :src="img.url"></div>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.left {
  width: 100%;
  display: flex;
  .left-title {
    width: 60px;
    height: 48px;
    color: #fff;
    text-align: center;
    line-height: 48px;
    font-size: 12px;
    cursor: pointer;
    &.active-assets-tilte {
      background-color: rgb(10, 11, 13);
    }
  }
  .left-img {
    flex: 1;
    padding: 16px;
    background-color: rgb(10, 11, 13);
    height: calc(100vh - 70px);
    overflow: auto;
    z-index: 999999;
    .desc {
      color: #fff;
      font-size: 12px;
      height: 22px;
      line-height: 22px;
      padding: 0 4px;
      background-color: rgb(33, 35, 38);
      cursor: pointer;
    }
    img {
      width: 100%;
      height: 85px;
      cursor: pointer;
    }
  }
}
::-webkit-scrollbar {
  width: 3px;
  height: 10px;
}
::-webkit-scrollbar-thumb {
  border-radius: 10px;
  background: #4B5563;
}

</style>
